// import get_params from '@dfeidao/atom-nodejs/authorization/get-params';
import { IFeidaoAiNodejsComponent } from '@dfeidao/atom-nodejs/interfaces';
// import whoami from '@dfeidao/atom-nodejs/msg/whoami';
import render1 from '@dfeidao/atom-nodejs/render/render';
import format from '@dfeidao/atom-web/dt/format';
import set from '@dfeidao/atom-web/global/set';
import nodejs from '@dfeidao/atom-web/msg/nodejs';
import p001 from './p001';
import p003 from './p003';
import p004 from './p004';

export default async function na001(fd: IFeidaoAiNodejsComponent) {
	// 页面初始化
	// 获取当前登录的用户信息
	// const user = await whoami(fd.data.actionid, fd.data.sessionid);
	// const users = await get_params(fd.data.msg, fd.data.headers, user.productid, '3');    // console.log('users', users);    // console.log(users.staff_name, users.staff_no);
	const a1 = "YG00000077";
	const staff_name = "梁日星";
	const productid = "kinth_cloud_100";
	set("staff_no", a1);
	set("staff_name", staff_name);
	set("productid", productid);
	// 查询数据
	const res1 = await nodejs<Array<{  notice_receive_no: string, inform_no: string, inform_title: string, inform_content: string, receive_time: number, sponso_no: string, sponsor: string }>>('notification-notice/zj-000001/s001',
		{
			filter: {
				pn: 1, a: a1
			}
		});
	// 查询条数
	// console.log(res1);
	const res2 = await nodejs('notification-notice/zj-000001/s002',
		{
			filter: {
				pn: 1, a: a1
			}
		});
	const arr1 = Array();
	const arr2 = Array();
	for (let i = 0; i < res2; i++) {
		arr2.push(res1[i].inform_no);
		arr1.push(format(res1[i].receive_time, 2));
	}
	// console.log(arr2);
	const newres1 = res1.map((n) => {
		return { ...n, receive_time: format(n.receive_time, 2) };
	});
	const res3 = await nodejs<{ dt: Array<{ inform_no: string, sponso_no: string, sponsor: string }> }>('notification-notice/zj-000001/s003',
		{
			filter: {
				arr: arr2
			}
		});
	// 数据合并
	// console.log(res3);
	const newarr = newres1.map((n) => {
		for (let i = 0; i < res3.dt.length; i++) {
			if (n.inform_no === res3.dt[i].inform_no) {
				n.sponso_no = res3.dt[i].sponso_no,
					n.sponsor = res3.dt[i].sponsor;
				return n;
			}
		}
		n.sponsor = "";
		return n;
	});
	if (newres1.length > 0) {
		render1(fd.data.node, newarr, p001, 'p001');
		if (res2 > 20) {
			render1(fd.data.node, res2, p004, 'p004');
		}
	} else {
		render1(fd.data.node, "", p003, 'p003');
	}

}
